package team.seekers.hula.course.resource.sectionContentComment.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.course.resource.sectionContentComment.entity.dto.SectionContentCommentAddDTO;
import team.seekers.hula.course.resource.sectionContentComment.entity.dto.SectionContentCommentQueryDTO;
import team.seekers.hula.course.resource.sectionContentComment.entity.dto.SectionContentCommentUpdateDTO;
import team.seekers.hula.course.resource.sectionContentComment.entity.vo.SectionContentCommentListVO;
import team.seekers.hula.course.resource.sectionContentComment.service.SectionContentCommentService;
import team.seekers.hula.auth.service.MindUtils;

/**
 * <p>
 * 回答的评论 前端控制器
 * </p>
 *
 * @author hbc
 * @since 2021-02-18
 */
@Controller
@ApiResponseBody
@RequestMapping("/section-content/comment")
public class SectionContentCommentController {

    @Autowired
    private SectionContentCommentService sectionContentCommentService;

    @PostMapping("/add")
    public void add(@RequestBody SectionContentCommentAddDTO addDTO){
        sectionContentCommentService.add(addDTO);
    }

    @GetMapping("/delete")
    public void delete(@RequestParam String id){
        sectionContentCommentService.delete(id);
    }

    @PostMapping("/replay")
    public void replay(@RequestBody SectionContentCommentUpdateDTO updateDTO){
        sectionContentCommentService.replay(updateDTO);
    }


    @PostMapping("/update")
    public void update(@RequestBody SectionContentCommentUpdateDTO updateDTO){
        sectionContentCommentService.update(updateDTO);
    }

    /**
     * 分页查询按照good排序
     */
    @GetMapping("/pageOrderByGood")
    public PageResult<SectionContentCommentListVO> pageOrderByGood(SectionContentCommentQueryDTO queryDTO){
        return sectionContentCommentService.pageOrderByGood(queryDTO);
    }

    /**
     * 分页查询按照创建时间排序
     */
    @GetMapping("/pageOrderByTime")
    public PageResult<SectionContentCommentListVO> pageOrderByTime(SectionContentCommentQueryDTO queryDTO){
        return sectionContentCommentService.pageOrderByTime(queryDTO);
    }

    /**
     * 分页查询按照good排序
     */
    @GetMapping("/pageMineOrderByTime")
    public PageResult<SectionContentCommentListVO> pageMineOrderByTime(SectionContentCommentQueryDTO queryDTO){
        queryDTO.setUserId(MindUtils.getUserId());
        return sectionContentCommentService.pageOrderByTime(queryDTO);
    }

    /**
     * 发现有相同的疑问，认为评论有用
     */
    @GetMapping("/wind")
    public void addWind(@RequestParam String sectionContentCommentId){
        sectionContentCommentService.addWind(sectionContentCommentId);
    }
}

